const mongoose =require("../util/db");

let userSchema =new mongoose.Schema({
    username:String,
    password:String,
})
//利用结构化的schema生成一个model
let UserModel =mongoose.model('user',userSchema);

//注册(添加),登录(查询)
module.exports={
    save:(userinfo)=>{
    let user =new UserModel(userinfo);
    return new Promise((resolve,reject)=>{
        user.save((err,docs)=>{
            if(err) reject();
            else resolve(docs);
        })
    })    
    },
    find:(userinfo)=>{
        return new Promise((resolve,reject)=>{
            UserModel.find(userinfo,(err,docs)=>{
                if(err) reject();
                else resolve(docs);
            })
        })
    }
}